package com.mes.cloud.security;

import com.netflix.zuul.ZuulFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * zuul拦截器
 * Created by Lenovo on 2017/9/18.
 */
@Configuration
public class ZuulConfiguration {
    @Bean
    public ZuulFilter commonPreFilter(ZuulListeners listeners) {
        return new ZuulFilter() {
            @Override
            public String filterType() {
                return "pre";
            }

            @Override
            public int filterOrder() {
                return 999;
            }

            @Override
            public boolean shouldFilter() {
                return true;
            }

            @Override
            public Object run() {
                listeners.beforeRequest();
                return null;
            }
        };
    }

    @Bean
    public ZuulFilter commonPostFilter(ZuulListeners listeners) {
        return new ZuulFilter() {
            @Override
            public String filterType() {
                return "post";
            }

            @Override
            public int filterOrder() {
                return 999;
            }

            @Override
            public boolean shouldFilter() {
                return true;
            }

            @Override
            public Object run() {
                listeners.afterResponse();
                return null;
            }
        };
    }
}
